package com.isaiah.graph.adjacencylist;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Title: ${file_name}
 * @Description: ${todo}
 * @author: Haijun
 * @emial: isaiah@sohu.com
 * @date 2020/6/816:10
 */
public class TrafficProject {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(TrafficProject.class.getClassLoader().getResourceAsStream("trffic_project.txt")));
        // 读取城市数目，初始化Graph图
        int num = Integer.parseInt(reader.readLine());
        Graph g = new Graph(num);
        //读取已经修建好的道路数目
        int roadNum = Integer.parseInt(reader.readLine());
        //循环读取已经修建好的道路，并调用addEdge方法
        for (int i = 0; i < roadNum; i++){
            String line = reader.readLine();
            int v = Integer.parseInt(line.split(" ")[0]);
            int w = Integer.parseInt(line.split(" ")[1]);
            g.addEage(v, w);
        }
        // 根据图G和顶点9构建图的搜索对象
        DepthFirstSearch search = new DepthFirstSearch(g, 9);
        //调用搜索对象的marked(10)方法和marked(8)方法
        System.out.println("9号城市和10号城市是否已相通：" + search.isVisited(10));
        System.out.println("9号城市和8号城市是否已相通：" + search.isVisited(8));

    }
}
